/**
 * Opportunity实体类
 *
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/1/15
 */
package com.sxf.crm.entity;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sxf.crm.enums.DeleteStatus;
import com.sxf.crm.enums.OpportunitySource;
import com.sxf.crm.enums.OpportunityStatus;
import jakarta.persistence.*;
import lombok.Data;
import java.math.BigDecimal;

/**
 * 商机实体类
 * 
 * <p>用于管理系统商机信息，包括商机基本信息、状态、金额等</p>
 * 
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/6/1
 */
@Data
@Entity
@Table(name = "opportunities")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Opportunity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "name", nullable = false)
    private String name; // 商机名称

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "customer_id")
    private Customer customer; // 关联的客户

    @Column(name = "amount")
    private BigDecimal amount; // 商机金额

    @Column(name = "expected_close_date")
    private Long expectedCloseDate; // 预计成交日期

    @Column(name = "description", columnDefinition = "TEXT")
    private String description; // 商机描述

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "owner_id")
    private User owner; // 商机负责人

    @Column(name = "status")
    @Enumerated(EnumType.STRING)
    private OpportunityStatus status = OpportunityStatus.UNASSIGNED; // 商机状态

    @Column(name = "win_probability")
    private Integer winProbability; // 赢单概率(0-100)

    @Column(name = "source")
    @Enumerated(EnumType.STRING)
    private OpportunitySource source; // 商机来源

    @Column(name = "competitor")
    private String competitor; // 竞争对手

    @Column(name = "next_step")
    private String nextStep; // 下一步计划

    @Column(name = "last_follow_up_time")
    private Long lastFollowUpTime; // 最后跟进时间

    @Column(name = "next_follow_up_time")
    private Long nextFollowUpTime; // 下次跟进时间

    @Column(name = "pause_reason")
    private String pauseReason; // 暂停原因

    @Column(name = "lost_reason")
    private String lostReason; // 丢失原因

    @Column(name = "remark")
    private String remark; // 备注信息

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "contact_id")
    private Contact contact; // 联系人

    @Column(name = "delete_status", nullable = false)
    @Enumerated(EnumType.ORDINAL)
    private DeleteStatus deleteStatus = DeleteStatus.NOT_DELETED;

    private Long createAt;

    @Column(name = "create_user_id")
    private Long createUserId;

    private Long updateAt;

    @Column(name = "update_user_id")
    private Long updateUserId;

    private Boolean recycled; // 是否被回收
    private Long recycleUserId; // 回收人ID
    private Long recycleTime; // 回收时间
    private String recycleReason; // 回收原因

    private Long rejectUserId; // 拒绝人ID
    private Long rejectTime; // 拒绝时间
    private String rejectReason; // 拒绝原因

} 